/********************************************************************************
 *      Copyright:  (C) 2022 Nikel
 *                  All rights reserved.
 *
 *       Filename:  times.h
 *    Description:  This head file 
 *
 *        Version:  1.0.0(08/05/22)
 *         Author:  zhouyanlin <www.zhouyanlin1222@qq.com>
 *      ChangeLog:  1, Release initial version on "08/05/22 09:59:39"
 *                 
 ********************************************************************************/

#ifndef  _TIMES_H_
#define  _TIMES_H_

#include <time.h>

typedef struct
{
	int         sample_interval;
	long int    current_time;
	long int    last_time;
	char        *times;
	time_t      tv;
	
} time_ctx_t;

/* ********************************************************************
 * FunctionName: determin_time
 * Function: Determine whether the sampling time is reached
 * Parameters: @struct my_time *t
 * Return: return 1 if ok, else return 0
 * Notes:
 * *********************************************************************/
static inline int determin_time(time_ctx_t *t)
{
	t->current_time = time(&t->tv);
	if((t->current_time - t->last_time) > t->sample_interval)
	{
		t->last_time = t->current_time;
		t->times = ctime(&t->tv);
		return 1;
	}

	return 0;
}

#endif   /* ----- #ifndef _TIMES_H_  ----- */
